package com.sqj.singletonPattern.Container;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainerSingleton {
    private ContainerSingleton(){}
    private static Map<String,Object> ioc=new ConcurrentHashMap<>(1);

    public static Object getBean(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        if(!ioc.containsKey(className)){
            Object obj=null;
            Class<?> clazz = Class.forName(className);
            obj = clazz.newInstance();
            ioc.put(className,obj);
            return obj;
        }else {
            return ioc.get(className);
        }

    }
}
